$(document).ready(function() {		
	// 第一次查询，无参数查询
	$.ajax( {
		type : "post",
		url : "wsq/Sched_find.action",
		success : showData
	});
	
	$("#query").click(function(){
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		var id=$("#scTime").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#PersonTable").fadeIn("fast");
		$("#loadingPerson").show();
		$.ajax({
  			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
 				  "timeStart":timeStart,
 				  "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#firstPage").click(function(){
		var total=$("#total").text();
		var page=1;
		var maxRow=$("#maxRow").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
  			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#prePage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		var maxRow=$("#maxRow").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		page=(parseInt(page)-1);
		if(page<=0){
			alert("第一页了");
			return ;
		}
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#nextPage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		if(page>pageCount){
			alert("最后一页了");
			return;
		}
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#lastPage").click(function(){
		var total=$("#total").text();
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#jumpPage").click(function(){
		var total=$("#total").text();
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var UId=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();		
		var page=$("#jump").val();
		if(page>pageCount){
			alert("页数过大");
			return;
		}
		
		if(page>pageCount){
			alert("jumpPage > pageCount");
			return;
		}
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("fast");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	function showData(data){
		$("#listPerson").empty();	
		if(data.pageUtil.list == null){
			$("#loadingPerson").hide();
			$("#nonePerson").show();
			$("#total").text(0);
			$("#page").text(0);
			$("#pageCount").text(0);
			$("#maxRow").text(0);
		}else{
			$("#listPerson").hide();
			$("#nonePerson").hide();
		    $("#loadingPerson").hide();
		    $.each(data.pageUtil.list,function(i,n){
				fillDataToHtml(n.tbDuty.duId, n.tbDetailShift.dsName, n.tbUser.UId, n.tbUser.UName, n.id.scTime, n.tbUser.UPhone);
		  	});
		$("#listPerson").show();
		$("#total").text(data.pageUtil.total);
		$("#page").text(data.pageUtil.page);
		$("#pageCount").text(Math.ceil(data.pageUtil.total/10));
		$("#maxRow").text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(duId,dsName,UId,UName,scTime,UPhone){
		var strHtml="<tr>";	
		strHtml+="<td ><div>"+duId+"</div></td>";	
		strHtml+="<td ><div>"+dsName+"</div></td>";
		strHtml+="<td ><div>"+UId+"</div></td>";
		strHtml+="<td ><div>"+UName+"</div></td>";	
		strHtml+="<td ><div>"+scTime.replace(/T/," ")+"</div></td>";
		strHtml+="<td ><div>"+UPhone+"</div></td>";
        strHtml+="</tr>";
        $("#listPerson").append(strHtml);
	}
	
	// 上传文件判断
	$("#uploadForm").validate({
		submitHandler: function(form){
		    var file=$('#file').val();
			form.submit();   // 提交表单
			$.ajax({
  				type: "post",
 				url: "wsq/UploadExcle_upload.action",
 				data:{
					"file":file
			    }
			});	
	    },
	    rules: {
	    	'file':'required'
	    },
	    messages: {
	    	'file':" "
	    }
	});
	
	// function showUp(data){
	// if(data.ajaxRST=='1'){
	// alert("保存成功");
	// $('#mainFrame',window.parent.document).attr('src','wsq/paiban1.jsp');
	// }else{
	// alert("上传文件填写不正确!");
	// }
	// }
	
	// $("#uploadForm").click(function(){
	// if(document.uploadForm.scTime.value == "" ){
	// alert("时间不能为空");
	// return false;
	// }
	// if(document.uploadForm.duId.value == "" ){
	// alert("岗位不能为空");
	// return false;
	// }
	// if(document.uploadForm.dsName.value == "" ){
	// alert("班次不能为空");
	// return false;
	// }
	// if(document.uploadForm.uId.value == "" ){
	// alert("登录名不能为空");
	// return false;
	// }
	// return true;
		
		// var
		// fileext=document.uploadForm.image.value.substring(document.uploadForm.image.value.lastIndexOf("."),document.uploadForm.image.value.length)
		// fileext=fileext.toLowerCase()
		// if
		// ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
		// {
		// alert("对不起，系统仅支持标准格式的照片，请您调整格式后重新上传，谢谢 !");
		// document.form1.image.focus();
		// }
		// else
		// {
		// document.form1.img.src = document.form1.image.value;
		// }
	//});
});

function check(){
	if(document.uploadForm.scTime.value == "" ){
		alert("时间不能为空");
		return false;
	}	
	if(document.uploadForm.duId.value == "" ){
		alert("岗位不能为空");
		return false;
	}
	if(document.uploadForm.dsName.value == "" ){
		alert("班次不能为空");
		return false;
	}	
	if(document.uploadForm.uId.value == "" ){
		alert("登录名不能为空");
		return false;
	}
	return true;
}